package com.ht.dao;

import java.sql.Connection;
import java.sql.SQLException;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

public class BaseDAO {

	private DataSource dataSource;

	public BaseDAO() {
		try {
			Context context = new InitialContext();
			Object object = context.lookup("java:/comp/env/datasource/mysql");
			if (object instanceof DataSource) {
				dataSource = (DataSource) object;
			}
		} catch (NamingException e) {
			e.printStackTrace();
		}
	}

	public Connection getConn() {
		try {
			return dataSource.getConnection();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}

}
